﻿@using RooHui.Infrastructure.Entities.Enum
@{
    ViewBag.Title = "Invest";
    Layout = "~/Views/Shared/_Member.cshtml";
}
@section head{
    <link type="text/css" href="/content/plugins/jquery-ui-1.10.0.custom/jquery-ui-1.10.0.custom.css"
        rel="stylesheet" />
    <!--[if lt IE 9]>
	    <link rel="stylesheet" type="text/css" href="/content/plugins/jquery-ui-1.10.0.custom/jquery.ui.1.10.0.ie.css"/>
    <![endif]-->
}
<div class="container" style="margin-top: 20px;">
    <div class="headline">
        <h2>
            我的投资</h2>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <form action="/member/invest" method="get" class="form-inline">
            @{
                string t = Request.QueryString["type"];
                int type = 0;
                if (!String.IsNullOrEmpty(t))
                {
                    if (Int32.TryParse(t, out type))
                    {
                        if (type < 0 || type > 3)
                        {
                            type = 0;
                        }
                    }
                }
            }
            <select name="type" id="sltType" class="input-small">
                <option value="0">全部</option>
                <option value="1">投标中</option>
                <option value="2">还款中</option>
                <option value="3">已完成</option>
            </select>
            <input type="text" id="txtstart" value="@Request.QueryString["start"]" name="start" class="input-small input-large" placeholder="起始时间" />
            -
            <input type="text" id="txtend" value="@Request.QueryString["end"]" name="end" class="input-small input-large" placeholder="结束时间" />
            <button type="submit" class="btn">
                筛选</button>
            </form>
        </div>
    </div>
    <div class="row-fluid" style="min-height: 400px;">
        @{
            RooHui.Infrastructure.Entities.ItemListBox<RooHui.Portal.Biz.Model.InvestmentItemsModel> list = ViewBag.Investments;
        }
        <table class="table">
            <thead>
                <tr>
                    <th width="20%">
                        产品
                    </th>
                    <th width="15%">
                        投资额
                    </th>
                    <th width="15%">
                        投资时间
                    </th>
                    <th width="15%">
                        起息时间
                    </th>
                    <th width="15%">
                        收益方式
                    </th>
                    <th>
                        年化收益率
                    </th>
                </tr>
            </thead>
            <tbody>
                @if (list != null && list.Data != null && list.Data.Any())
                {
                    foreach (var item in list.Data)
                    {
                    <tr>
                        <td>
                            <a target="_blank" href="/member/orderdetail?id=@item.OrderId">
                                @item.ProductName @item.ProjectCode
                                @if (item.ProjectStatus < RooHui.Infrastructure.Entities.Enum.ProjectStatus.Repayment)
                                {
                                    <strong class="orange">[@item.ProjectStatus.Mapping()]</strong>
                                }
                                else
                                {
                                    <strong class="green">[@item.ProjectStatus.Mapping()]</strong>
                                }
                            </a>
                        </td>
                        <td>
                            ￥ @item.Amount.ToString("F2")
                        </td>
                        <td class="hidden-sm">
                            @item.InvestDate.ToString("yyyy.MM.dd HH:mm")
                        </td>
                        <td>
                            @item.BeginDate.ToString("yyyy.MM.dd")
                        </td>
                        <td>
                            @item.Policies.First(c => !c.IsAttach).BalanceType.Mapping()
                        </td>
                        <td>
                            <span class="orange">@((item.Policies.FirstOrDefault(c => !c.IsAttach).Rate).ToString("F2"))
                                %
                                @if (item.Policies.Any(c => c.IsAttach))
                                {
                                    @:+ 奖励
                                                                                                                                                        }
                            </span>
                        </td>
                    </tr>
                    }
                }
            </tbody>
        </table>
    </div>
    @Html.Raw(list.PageItemSegment)
</div>
@section scripts{
    <script type="text/javascript" src="/content/plugins/jquery-ui-1.10.0.custom/jquery-ui-1.10.0.custom.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#sltType').val(@type);
            $('#labinvest').addClass('active');
            $('#txtstart').datepicker({
                //defaultDate: +1,
                dateFormat: 'yy/mm/dd',
                firstDay: 1,
                maxDate: new Date(),
                numberOfMonths: 2,
                inline: true
            });
            $('#txtend').click(function () {
                var minDate = null;
                if ($('#txtstart').val() != '') {
                    minDate = new Date($('#txtstart').val());
                }
                if (!$(this).datepicker('option', 'numberOfMonths')) {
                    $(this).datepicker({
                        //defaultDate: +1,
                        dateFormat: 'yy/mm/dd',
                        firstDay: 1,
                        minDate: minDate?'':minDate,
                        maxDate: '+7m',
                        numberOfMonths: 2,
                        maxDate: new Date(),
                        inline: true
                    }).focus();
                } else {
                    $(this).datepicker('option', 'minDate', new Date($('#txtstart').val())).focus();
                }
            });
        });
    </script>
}
